﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;


        

namespace Project
{
    public partial class addStudent : Form
    {
        private OleDbConnection bookConn;
        private OleDbCommand oleDbCmd = new OleDbCommand();
        //parameter from mdsaputra.udl
        private String connParam = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Properties.Settings.Default.database + ";Persist Security Info=False";
        public addStudent()
        {
            bookConn = new OleDbConnection(connParam);
            InitializeComponent();
            
          
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            bookConn.Open();
            oleDbCmd.Connection = bookConn;
           // oleDbCmd.CommandText = "insert into student (fName, lName, studentID, dob, phone, email, unit, street, suburb, state, post) values ('" + this.txtFname.Text + "','" + this.txtLname.Text + "','" + this.txtID.Text + "','" + this.txtdob.Text + "','" + this.txtcontact.Text + "','" + this.txtemail.Text + "','" + this.txtunit.Text + "','" + this.txtstreet.Text + "','" + this.txtsuburb.Text + "','" + this.txtstate.Text + "','" + this.txtpost.Text + "');";
            try
            {
                int temp = oleDbCmd.ExecuteNonQuery();
                if (temp > 0)
                {
                    txtFname.Text = null;
                    txtLname.Text = null;
                    txtID.Text = null;
                    
                    txtemail.Text = null;
                   
                    MessageBox.Show("Record Successfuly Added");
                }
                else
                {
                    MessageBox.Show("Record Fail to Added");
                }
            }
             catch
            {
                MessageBox.Show("Record Fail to Added");
            }
            bookConn.Close();
        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {
            
        }
    }
}
